
/*
 * File: dht11_test.ino
 * Desc: Get humidity and temperature from DHT11 sensor
 * Auth: RudyLo
 * Date: 06/12/2019
 */

#include "dht11.h"

#define DHT_PIN 2

DHT11 dht11(DHT_PIN);

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
}

void loop()
{
  // Wait a few seconds between measurements.
  delay(2000);

  int ret = dht11.read();

  if(ret == DHTLIB_ERROR_CHECKSUM) {
    Serial.println("(E) Checksum failed");
    return;
  }
  else if(ret == DHTLIB_ERROR_TIMEOUT) {
    Serial.println("(E) Read time out");
    return;
  }

  Serial.print("Humidity: ");
  Serial.print((float)dht11.getHumidity(), 2);

  Serial.print("%  Temperature: ");
  Serial.print((float)dht11.getTemperature(), 2);

  Serial.print("'C  ");
  Serial.print((float)dht11.getTemperature(true), 2);
  Serial.println("'F");
}
